package com.ruoyi.web.controller.class_management;

import com.ruoyi.class_management.domain.TbClass;
import com.ruoyi.class_management.service.ITbClassService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 班级Controller
 *
 * @author hongyi
 * @date 2023-12-26
 */
@RestController
@RequestMapping("/class_management/class")
public class TbClassController extends BaseController
{
    @Autowired
    private ITbClassService tbClassService;

    /**
     * 查询班级列表
     */
    @PreAuthorize("@ss.hasPermi('class_management:class:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbClass tbClass)
    {
        startPage();
        List<TbClass> list = tbClassService.selectTbClassList(tbClass);
        return getDataTable(list);
    }

    /**
     * 导出班级列表
     */
    @PreAuthorize("@ss.hasPermi('class_management:class:export')")
    @Log(title = "班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbClass tbClass)
    {
        List<TbClass> list = tbClassService.selectTbClassList(tbClass);
        ExcelUtil<TbClass> util = new ExcelUtil<TbClass>(TbClass.class);
        util.exportExcel(response, list, "班级数据");
    }

    /**
     * 获取班级详细信息
     */
    @PreAuthorize("@ss.hasPermi('class_management:class:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tbClassService.selectTbClassById(id));
    }

    /**
     * 新增班级
     */
    @PreAuthorize("@ss.hasPermi('class_management:class:add')")
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbClass tbClass)
    {
        return toAjax(tbClassService.insertTbClass(tbClass));
    }

    /**
     * 修改班级
     */
    @PreAuthorize("@ss.hasPermi('class_management:class:edit')")
    @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbClass tbClass)
    {
        return toAjax(tbClassService.updateTbClass(tbClass));
    }

    /**
     * 删除班级
     */
    @PreAuthorize("@ss.hasPermi('class_management:class:remove')")
    @Log(title = "班级", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbClassService.deleteTbClassByIds(ids));
    }
}
